package com.hb.config;

import com.hb.concert.CriticAspect;
import com.hb.concert.Performance;
import com.hb.impl.CriticismEngineImpl;
import com.hb.impl.DefaultPerformance;
import com.hb.interfaces.CriticismEngine;
import org.aspectj.lang.Aspects;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableAspectJAutoProxy
public class CriticConfig {
    @Bean
    public Performance performance() {
        return new DefaultPerformance();
    }

    @Bean
    public CriticismEngine criticismEngine() {
        CriticismEngineImpl impl = new CriticismEngineImpl();
        List<String> criticismPoolList = new ArrayList<>();
        criticismPoolList.add("Worst performance ever!");
        criticismPoolList.add("I laughed, I cried, then I realized I was at the wrong show.");
        criticismPoolList.add("A must see show!");
        impl.setCriticismPool((String[]) criticismPoolList.toArray());
        return impl;
    }

    @Bean
    public Object criticAspect() {
        CriticAspect aspect = Aspects.aspectOf(CriticAspect.class);
        aspect.setCriticismEngine(criticismEngine());
        return criticAspect();
    }
}
